package com.ruoyi.web.publish.usefunds.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.publish.usefunds.mapper.UsefundsMapper;
import com.ruoyi.web.publish.usefunds.domain.Usefunds;
import com.ruoyi.web.publish.usefunds.service.IUsefundsService;

/**
 * 资金用途说明Service业务层处理
 *
 * @author houxuzhong
 * @date 2021-08-25
 */
@Service
public class UsefundsServiceImpl implements IUsefundsService
{
    @Autowired
    private UsefundsMapper usefundsMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询资金用途说明
     *
     * @param id 资金用途说明主键
     * @return 资金用途说明
     */
    @Override
    public Usefunds selectUsefundsById(Long id)
    {

        return usefundsMapper.selectUsefundsById(id);
    }

    /**
     * 查询资金用途说明列表
     *
     * @param usefunds 资金用途说明
     * @return 资金用途说明
     */
    @Override
    public List<Usefunds> selectUsefundsList(Usefunds usefunds)
    {
        return usefundsMapper.selectUsefundsList(usefunds);
    }

    /**
     * 查询资金用途说明列表
     *
     * @param usefunds 资金用途说明
     * @return 资金用途说明
     */
    @Override
    public List<Usefunds> selectMyUsefundsList(Usefunds usefunds) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        usefunds.setCreateById(user.getUserId());
        return usefundsMapper.selectUsefundsList(usefunds);
    }

    /**
     * 新增资金用途说明
     *
     * @param usefunds 资金用途说明
     * @return 结果
     */
    @Override
    public int insertUsefunds(Usefunds usefunds)
    {
        usefunds.setCreateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        usefunds.setCreateById(user.getUserId());
        usefunds.setCreateBy(user.getUserName());
        return usefundsMapper.insertUsefunds(usefunds);
    }

    /**
     * 修改资金用途说明
     *
     * @param usefunds 资金用途说明
     * @return 结果
     */
    @Override
    public int updateUsefunds(Usefunds usefunds)
    {
        usefunds.setUpdateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        usefunds.setUpdateById(user.getUserId());
        usefunds.setUpdateBy(user.getUserName());
        return usefundsMapper.updateUsefunds(usefunds);
    }

    /**
     * 批量删除资金用途说明
     *
     * @param ids 需要删除的资金用途说明主键
     * @return 结果
     */
    @Override
    public int deleteUsefundsByIds(Long[] ids)
    {
        return usefundsMapper.deleteUsefundsByIds(ids);
    }

    /**
     * 删除资金用途说明信息
     *
     * @param id 资金用途说明主键
     * @return 结果
     */
    @Override
    public int deleteUsefundsById(Long id)
    {
        return usefundsMapper.deleteUsefundsById(id);
    }
}
